package com.dev.stream;

import com.dev.pojo.Item;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 戴 骥
 * @date 2021-08-22 15:54
 */
public class BaseStream {
    @Test
    public void StreamTest() {
        /*
         * 基础操作
         */
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item(11, "小牙刷", 12.05));
        itemList.add(new Item(5, "日本马桶盖", 999.05));
        itemList.add(new Item(7, "格力空调", 888.88));
        itemList.add(new Item(17, "肥皂", 2.00));
        itemList.add(new Item(9, "冰箱", 4200.00));
        itemList.forEach(System.out::println);
        System.out.println("=====分割=======");

        /*
         * 老方法
         */
        ArrayList<Object> objects = new ArrayList<>();
        for (Item item : itemList) {
            if (item.getId() == 11) {
                objects.add(item);
            }
        }
        objects.forEach(System.out::println);
        System.out.println("=====分割=======");

        /*
         * Stream处理方法
         */
        List<Item> collect = itemList.stream().filter(t -> t.getPrice() == 12.05).collect(Collectors.toList());
        collect.forEach(System.out::println);

    }

}
